package com.gitee.ywj1352.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.MapPropertySource;

import java.util.HashMap;
import java.util.List;

/**
 * @author wenjie.yang on 2019/7/18.
 */
@SpringBootApplication
@EnableConfigServer
public class SpringConfigApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringConfigApplication.class,args);
    }


    //添加Bean对象导致 DefaultRepositoryConfiguration 没有被激活
    //自己想实现就 重写这个类
    @Bean
    public EnvironmentRepository environmentRepository(){
        return new EnvironmentRepository(){
            @Override
            public Environment findOne(String application, String profile, String label) {
                Environment environment = new Environment("default",profile,label);
                List<PropertySource>  propertySources = environment.getPropertySources();
                HashMap<String,Object> map = new HashMap<>();
                map.put("name","杨文杰");
                PropertySource source = new PropertySource("map",map);
                propertySources.add(source);
                return environment;
            }
        };
    }


}
